package demo.view;

import demo.controller.StudentController;
import demo.controller.UserController;
import demo.entity.Student;

import java.util.Scanner;

public class StudentView {

    private StudentController studentController = new StudentController();

    private UserController userController =  new UserController();

    private Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        StudentView studentView = new StudentView();
        studentView.view();
    }

    public void view(){

        kg();

        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println("-----------------------欢迎进入XXX管理系统-----------------------");
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();

        while(true) {
            System.out.println("***************************请登录***************************");
            System.out.print("请输入用户名：");
            String userName = sc.next();
            System.out.print("请输入密码：");
            String passWord = sc.next();
            if (userController.login(userName, passWord)) {
                while (true){
                    studentView();
                }
            } else {
                System.out.println("登录失败");
            }

        }

    }

    private void studentView(){
        System.out.println("1、添加学生\t2、删除学生\t3、修改学生\t4、根据学号查学生信息\t5、查询所有学生\t6、学生姓名关键字查询\t7、退出\t其他");
        int option = sc.nextInt();
        switch (option) {
            case 1:
                System.out.println("欢迎使用添加学生功能");
                Boolean b = studentController.addStudent();
                if (b) {
                    System.out.println("添加成功");
                } else {
                    System.out.println("添加失败");
                }
                break;
            case 2:
                System.out.println("欢迎使用删除学生功能");
                Boolean b1 = studentController.deleteStudent();
                if (b1) {
                    System.out.println("删除成功");
                } else {
                    System.out.println("删除失败");
                }
                break;
            case 3:
                System.out.println("欢迎使用修改学生功能");
                Boolean b2 = studentController.updateStudent();
                if (b2) {
                    System.out.println("修改成功");
                } else {
                    System.out.println("修改失败");
                }
                break;
            case 4:
                System.out.println("请输入要查询的学生的id");
                Student student = studentController.selectOneStudent();
                if (student == null) {
                    System.out.println("没有查询到该学生！");
                    break;
                }
                System.out.println(student.toString());
                break;
            case 5:
                System.out.println("欢迎使用查询所有学生功能");
                studentController.selectAllStudent();
                break;
            case 6:
                System.out.println("请输入你的搜索");
                studentController.searchStudent();
                break;
            case 7:
                System.out.println("欢迎下次使用");
                System.exit(0);
                return;
            default:
                System.out.println("输入有误，请重新输入");
                break;
        }
    }

    public static void kg() {
        System.out.println("                       _oo0oo_");
        System.out.println("                      o8888888o");
        System.out.println("                     88\" . \"88");
        System.out.println("                      (| -_- |)");
        System.out.println("                     0\\  =  /0");
        System.out.println("                    ___/`---'\\___");
        System.out.println("                  .' \\|     |// '.");
        System.out.println("                / _||||| -:- |||||- \\");
        System.out.println("               |   | \\\\\\  -  /// |   |");
        System.out.println("               | \\_|  ''\\---/''  |_/ |");
        System.out.println("               \\  .-\\__  '-'  ___/-. /");
        System.out.println("             ___'. .'  /--.--\\  `. .'___");
        System.out.println("          .\"\" '<  `.___\\_<|>_/___.' >' \"\".");
        System.out.println("         | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |");
        System.out.println("         \\  \\ `_.   \\_ __\\ /__ _/   .-` /  /");
        System.out.println("     =====`-.____`.___ \\_____/___.-`___.-'=====");
        System.out.println("                       `=---='");
        System.out.println("                                                ");
        System.out.println("                                                ");
        System.out.println("     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ");
        System.out.println("                    佛祖保佑         永无BUG         ");
    }

}
